package com.struts2.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.struts2.model.Product_line;
import com.struts2.service.ProductListService;


public class ProductListAction extends ActionSupport implements ModelDriven<List<Product_line>>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String gender;
	private String type;
	private String category;
	private List<String> leftSideMenuList;
	private List<String> leftSideSubMenuList;
	private int productPerPage = 10;
	private int pageNum =1;
	private int maxPage =0;
	private List<Product_line> product_line;



	public String execute() {
 
		ProductListService productListService = new ProductListService();
		product_line = productListService.GetProductList(product_line,productPerPage, pageNum, gender, type, category);
		
		
		double a = Math.ceil((double)productListService.GetProductCount(product_line, gender, type, category)/productPerPage);
		setMaxPage((int)a);
		
		leftSideMenuList = new ArrayList<String>();
	//	leftSideMenuList.add("menu1");
	//	leftSideMenuList.add("menu2");
	//	leftSideMenuList.add("menu3");
		leftSideMenuList = productListService.getLeftSideMenu(leftSideMenuList, gender, type, category);
		
		leftSideSubMenuList = new ArrayList<String>();

		if(category!="")
		{
			leftSideSubMenuList = productListService.getLeftSubSideMenu(leftSideSubMenuList, gender, type, category);
			// leftSideSubMenuList.add("menu3");
		}
		//System.out.println("size: " + users.size());
		System.out.println(product_line);
		System.out.println(gender + "  \n" + type +"  \n" + category);
		return SUCCESS;
	}




	@Override
	public List<Product_line> getModel() {
		// TODO Auto-generated method stub
		return product_line;
	}



	//***********************************************

	public List<Product_line> getProduct_line() {
		return product_line;
	}


	public void setProduct_line(List<Product_line> product_line) {
		this.product_line = product_line;
	}

	public String getGender() {
		return gender;
	}


	public void setGender(String gender) {
		this.gender = gender;
	}


	public String getCategory() {
		return category;
	}


	public void setCategory(String category) {
		this.category = category;
	}


	public String getType() {
		return type;
	}


	public void setType(String type) {
		this.type = type;
	}


	
	public int getPageNum() {
		return pageNum;
	}


	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}


	public int getMaxPage() {
		return maxPage;
	}


	public void setMaxPage(int maxPage) {
		this.maxPage = maxPage;
	}


	public List<String> getLeftSideMenuList() {
		return leftSideMenuList;
	}


	public void setLeftSideMenuList(List<String> leftSideMenuList) {
		this.leftSideMenuList = leftSideMenuList;
	}


	public List<String> getLeftSideSubMenuList() {
		return leftSideSubMenuList;
	}


	public void setLeftSideSubMenuList(List<String> leftSideSubMenuList) {
		this.leftSideSubMenuList = leftSideSubMenuList;
	}
	
	/////////////////////////////////////////////////

	



	
	
}
